
package com.epam.android.training.day10;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;

public class EditItemActivity extends Activity {
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.edit_item);
        final EditText editName = (EditText) findViewById(R.id.edit_name);
        final EditText editMail = (EditText) findViewById(R.id.edit_email);
        final Intent intent = getIntent();
        editMail.setText(intent.getCharSequenceExtra(Day10Activity.MAIL_KEY));
        editName.setText(intent.getCharSequenceExtra(Day10Activity.NAME_KEY));

        final Button buttonUpdateInDatabase = (Button) findViewById(R.id.button_update_in_database);
        buttonUpdateInDatabase.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                intent.putExtra(Day10Activity.NAME_KEY, editName.getText());
                intent.putExtra(Day10Activity.MAIL_KEY, editMail.getText());
                setResult(Day10Activity.RESULT_UPDATE, intent);
                finish();
            }
        });

        final Button buttonDelete = (Button) findViewById(R.id.button_delete);
        buttonDelete.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                setResult(Day10Activity.RESULT_DELETE, intent);
                finish();
            }
        });
    }
}
